class Solution {
public:




    int countDays(int days, vector<vector<int>>& meetings) {

        vector<pair<int, int>> meet;

        for (int i = 0; i < meetings.size(); i++)
        {
            meet.push_back({ meetings[i][0], meetings[i][1] });
        }

        sort(meet.begin(), meet.end());

        // for (int i = 0; i < meet.size(); i ++)
        // {
        //     cout << meet[i].first << "  " << meet[i].second << endl;
        // }


        int cnt = meet[0].second - meet[0].first + 1;

        int n = meet.size();

        int st = meet[0].first, ed = meet[0].second;

        for (int i = 1; i < n; i++)
        {
            if (meet[i].first > ed)
            {
                cnt += meet[i].second - meet[i].first + 1;
                ed = meet[i].second;
            }

            else if (meet[i].first <= ed)
            {
                if (meet[i].second > ed)
                    cnt += meet[i].second - ed;

                ed = max(ed, meet[i].second);
            }
        }

        return days - cnt;

    }
};